

*------------------------------------------------------------------------------*
* Authors: 		Sabine C. Carey (University of Mannheim) and 
*				Juergen Brandsch (KfW Development Bank)
* Article: 		Borders and bullies: How borders shape perceptions of security and foreign policy preferences
* Journal: 		Research & Politics 
* Date: 		2024-01
* Instructions: This do file replicates descriptive Figures 1-3.
* Stata:		All estimations were done with Stata 18. 			
*------------------------------------------------------------------------------*

clear
set more off

*--------------------------------------------------
* Install packages
*--------------------------------------------------
*	for plotting percentages
	ssc install catplot
	
*	for graph labelling
	ssc install mylabel
	
* 	for combining graphs
	net install grc1leg,from( http://www.stata.com/users/vwiggins/) 


*--------------------
* Load data
*--------------------
use "cb_Georgia_data_prep.dta"

	
*--------------------------------------------------
* Figure 1. Border insecurity as severe personal security risk 
*--------------------------------------------------

foreach var of var close_0* {
	tab borderinsec `var', col
}

*** Ttest for the figures shown in this graph	)
	ttest borderinsec if close_01 < 2, by(close_SO_01)
	ttest borderinsec if close_02 < 2, by(close_SO_02)
	ttest borderinsec if close_03 < 2, by(close_SO_03)
	ttest borderinsec if close_04 < 2, by(close_SO_04)	
	
	ttest borderinsec if close_01 != 1, by(close_AB_01)
	ttest borderinsec if close_02 != 1, by(close_AB_02)
	ttest borderinsec if close_03 != 1, by(close_AB_03)
	ttest borderinsec if close_04 != 1, by(close_AB_04)	

tab close_01 borderinsec, matcell(freq)
	mata: st_matrix("freq", (st_matrix("freq") :/ rowsum(st_matrix("freq"))))
	mat li freq
	svmat freq, name(insec_perc_01)
	list insec_perc_012 in 1/3
	drop insec_perc_011

tab close_02 borderinsec, matcell(freq)
	mata: st_matrix("freq", (st_matrix("freq") :/ rowsum(st_matrix("freq"))))
	mat li freq
	svmat freq, name(insec_perc_02)
	list insec_perc_022 in 1/3
	drop insec_perc_021

tab close_03 borderinsec, matcell(freq)
	mata: st_matrix("freq", (st_matrix("freq") :/ rowsum(st_matrix("freq"))))
	mat li freq
	svmat freq, name(insec_perc_03)
	list insec_perc_032 in 1/3
	drop insec_perc_031

tab close_04 borderinsec, matcell(freq)
	mata: st_matrix("freq", (st_matrix("freq") :/ rowsum(st_matrix("freq"))))
	mat li freq
	svmat freq, name(insec_perc_04)
	list insec_perc_042 in 1/3
	drop insec_perc_041

keep insec_perc_0*
drop in 4/l

gen region=[_n]
recode region 1=0 2=1 3=2
	label define close 0 "Outside border region"	///
		1 "Within SO border region" 2 "Within AB border region", replace
	label values region close

rename insec_perc_012 b_insec_01 
rename insec_perc_022 b_insec_02
rename insec_perc_032 b_insec_03 
rename insec_perc_042 b_insec_04

* turn values into percentages
foreach var of var b_insec_0* {
	replace `var' = (`var')*100
	format `var' %9.3f
}
save "borderinsec_perc.dta", replace

* graph 
	#delimit ;
			graph hbar (sum) b_insec_0*, 
			over(region, gap(80)
			relabel(
				1 `""Outside border" "regions"'
				2 `""SO border" "region"'	/// 
				3 `""AB border" "region"')
			label(labsize(small))) 
			outergap(*1.5)
			graphregion(color(white))
				blabel(bar, position(inside) format(%4.0f) color(white))	
				bargap(10)
			ttext(60 62  "***" "", place(e) size(small) orientation(horizontal) col(black) )	
			ttext(54.5 54  "***" "", place(e) size(small) orientation(horizontal) col(black) )
			ttext(55 47  "***" "", place(e) size(small) orientation(horizontal) col(black) )
			ttext(55 40  "***" "", place(e) size(small) orientation(horizontal) col(black) )
			ttext(25 29  "***" "", place(e) size(small) orientation(horizontal) col(black) )	
			ttext(35 21  "*" "", place(e) size(small) orientation(horizontal) col(black) )
			ttext(32 14  "**" "", place(e) size(small) orientation(horizontal) col(black) )
			ttext(31 7  "***" "", place(e) size(small) orientation(horizontal) col(black) )			
			yl(0(20)70, nogrid)	
			ytitle("Percentage within region")
			note("Note: The stat. sign. levels refer to the difference in means between the border region and the equivalent region" "outside both border regions, *** p<0.001, ** p<0.01 * p<0.05")
			legend(pos(5) ring(0) row(4) col(1) size(small) 
				bmargin(vsmall) 
				region(lcolor(white))
				lab(1 "0.1° cut-off")
				lab(2 "0.2° cut-off")
				lab(3 "0.3° cut-off")
				lab(4 "0.4° cut-off")
				symxsize(*.5))
			scheme(stmono2)	
			;
		# delimit cr
		graph export "Figure_1.pdf", as(pdf) replace


*--------------------------------------------------
* Figure 2. Should Georgia use force to prevent SO border change?
*--------------------------------------------------
		
* Loading data
	use "cb_Georgia_data_prep.dta"
	
* Graph across by region
	tab border_force close_03, col
	
	* t-test
		ttest border_force, by(close_SO_03)
		ttest border_force, by(close_AB_03)
	
	#delimit;
	catplot border_force close_03, percent(close_03) asyvar stack
		blabel(bar, position(inside) format(%4.0f) color(white))	
		bargap(10)
		yl( , nogrid)	
		ytitle("Percentage")
		legend(row(1) col(3) size(small) bmargin(vsmall) pos(6) region(lcolor(white)))
		scheme(stmono2)	
	;
	delimit cr
	graph export "Figure_2.pdf", as(pdf) replace

	
*--------------------------------------------------
* Figure 3. Preferred military partner
*--------------------------------------------------

	tab NATO_EU close_01, col 
	tab Russia close_01, col 
	tab NATO_EU close_03, col 
	tab Russia close_03, col 
	
	* graph partner preferences within 0.1° border regions
		mylabels 0(5)55, myscale(@/100) local(labels)
		
		#delimit ;
			graph hbar NATO_EU Russia, 
			over(close_01, gap(120)
			relabel(
				1 `""Outside border regions" "N=1,610"'
				2 `""SO border region" "N=300"'	/// 
				3 `""AB border region" "N=212"')
			label(labsize(small))) 
			outergap(*1.5)
			graphregion(color(white))
			legend(off)
			ytitle("")
			ylabel(`labels', nogrid)	
			subtitle("0.1° Border regions")	
			name(partner_01border, replace)
			scheme(stmono2)	
			;
		# delimit cr
		
	* graph partner preferences within 0.3° border regions
		mylabels 0(5)55, myscale(@/100) local(labels)
		#delimit ;
			graph hbar NATO_EU Russia,
			over(close_03, gap(120)
			relabel(
				1 `""Outside border regions" "N=787"'
				2 `""SO border region" "N=843"'	/// 
				3 `""AB border region" "N=492"')
			label(labsize(small))) 
			outergap(*1.5)
			graphregion(color(white))
			legend(label(1 "NATO/EU") label(2 "Russia") row(1) size(small) bmargin(small)  region(lcolor(white)))
			ytitle("Percentage of respondents within region", size(small))
			ylabel(`labels', nogrid)
			ytick(0.05(0.1)0.35)	
			subtitle("0.3° Border regions")	
			name(partner_03border, replace)
			scheme(stmono2)	
			;
		# delimit cr		

	* combine graphs 0.1 and 0.3	
	#delimit ;
	 grc1leg partner_01border partner_03border, 	
			col(1) xsize(7)
			graphregion(color(white))	
			legendfrom(partner_03border)
		;	
	# delimit cr	
	graph export "Figure_3.pdf", as(pdf) replace
		
	
* END descriptive figures
